package com.itboye.mengwu.data.repository;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.core.utils.BaseErrorListener;
import com.itboye.core.utils.BaseSuccessReqListener;
import com.itboye.core.utils.ByJsonRequest.Builder;
import com.itboye.mengwu.data.interfaces.IGoodsDetail;
import com.itboye.mengwu.data.model.GoodsAskQueryModel;
import com.itboye.mengwu.data.model.GoodsCommentsModel;
import com.itboye.mengwu.data.model.GoodsDetailBean;
import com.itboye.mengwu.data.model.StoreDiscountBean;
import com.itboye.mengwu.ui.shop.GoodsDetailsRootBean;

public class GoodsDetailRepository extends BaseNetRepository implements
		IGoodsDetail<GoodsDetailBean> {
	String api = "100";
	public static final String GOODSDETAIL = "BY_Product_detail";// 5.3 查看商品详情
	public static final String StorePromotionSTR = "BY_StorePromotion_getInfo"; // 5.8
																				// 店铺优惠查询
	public static final String GoodsQuerySave = "BY_Product_ask";// 5.6 商品咨询保存
	public static final String GoodsQuery = "BY_Product_queryFaq";// 5.7 商品咨询查询
	public static final String GoodsComments = "BY_Product_comment";// 商品评论查询
	public static final String GoodsFenye = "BY_Product_comment";// 商品分页查询

	public GoodsDetailRepository(ICompleteListener listener) {
		super(listener);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void add(GoodsDetailBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(GoodsDetailBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(GoodsDetailBean model) {
		// TODO Auto-generated method stub

	}

	/**
	 * 查看商品评论
	 */
	@Override
	public void getInfo(GoodsDetailBean model) {
		Type type = new TypeToken<GoodsCommentsModel>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", model.getCate_id());// uid
		params.put("pid", model.getId());

		// 目前最简化调用
		// START
		(new Builder<GoodsCommentsModel>())
				.setTypeVerParamsAndReturnClass(GoodsComments, apiVer, params,
						type)
				.requestListener(
						new BaseSuccessReqListener<GoodsCommentsModel>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public List<GoodsDetailBean> queryYouHuiQuan(GoodsDetailBean model) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 5.3 查看商品详情
	 */
	@Override
	public void queryGoods(String pid, String uid) {
		Type type = new TypeToken<GoodsDetailsRootBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", uid);
		params.put("pid", pid);

		// 目前最简化调用
		// START
		(new Builder<GoodsDetailsRootBean>())
				.setTypeVerParamsAndReturnClass(GOODSDETAIL, apiVer, params,
						type)
				.requestListener(
						new BaseSuccessReqListener<GoodsDetailsRootBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/**
	 * 5.8 店铺优惠查询
	 */

	@Override
	public void StorePromotion(String store_id) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<StoreDiscountBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("store_id", store_id);

		// 目前最简化调用
		// START
		(new Builder<StoreDiscountBean>())
				.setTypeVerParamsAndReturnClass(StorePromotionSTR, apiVer,
						params, type)
				.requestListener(
						new BaseSuccessReqListener<StoreDiscountBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/**
	 * 5.6商品咨询保存
	 */
	@Override
	public void AskGoodsSave(String pid, String ask_content, String ask_uid,
			String ask_username) {
		// TODO Auto-generated method stub
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("pid", pid);// 商品id
		params.put("ask_content", ask_content);// 咨询内容
		params.put("ask_uid", ask_uid);// 咨询 用户ID
		params.put("ask_username", ask_username);// 咨询 用户名

		// 目前最简化调用
		// START
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(StorePromotionSTR, apiVer,
						params, String.class)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/**
	 * 5.7 商品咨询查询
	 */
	@Override
	public void GoodsQuery(String pid, String page_no, String page_size) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<GoodsAskQueryModel>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("pid", pid);
		// params.put("page_no", page_no);//页码，【默认1】
		// params.put("page_size", page_size)//页码大小，【默认10】

		// 目前最简化调用
		// START
		(new Builder<GoodsAskQueryModel>())
				.setTypeVerParamsAndReturnClass(GOODSDETAIL, apiVer, params,
						type)
				.requestListener(
						new BaseSuccessReqListener<GoodsAskQueryModel>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

}
